package com.zeny.coding.dto;


import com.zeny.coding.util.DtoUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.util.StringUtils;

import javax.xml.bind.ValidationException;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class TeacherDto {
    private String id;

    private String name;

    private String nickname;

    private String image;

    private String position;

    private String motto;

    private String intro;

    public void isValidForSave() throws ValidationException {
        valid();
        if (!StringUtils.isEmpty(this.id)) {
            this.id = null;
        }
    }

    public void isValidForUpdate() throws ValidationException {
        DtoUtil.valid(this.id, true, 1, 19);
        valid();
    }


    private void valid() throws ValidationException {
        DtoUtil.valid(this.name, true, 1, 50);
        DtoUtil.valid(this.nickname, true, 1, 50);
        DtoUtil.valid(this.position, true, 1, 50);
        DtoUtil.valid(this.motto, false, 1, 50);
        DtoUtil.valid(this.intro, false, 1, 500);
    }
}